import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Button',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyStatelessWidget(),
    );
  }
}

class MyStatelessWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //定义文本样式

    return Scaffold(
      appBar: AppBar(
        title: Text("Button"),
      ),
      body: Column(
        children: <Widget>[
          new MyDropDownButton()
        ],
      ),
    );
  }

}


class MyDropDownButton extends StatefulWidget{

  @override
  State<StatefulWidget> createState() {
    return _MyDropDownButton();
  }

}

class _MyDropDownButton extends State<MyDropDownButton>{
  List getCityList(){
    List<DropdownMenuItem> cityList = new List();
    cityList.add(DropdownMenuItem(
      child: new Text("上海"),
      value: "shanghai",
    ));
    cityList.add(DropdownMenuItem(
      child: new Text("北京"),
      value: "beijing",
    ));
    cityList.add(DropdownMenuItem(
      child: new Text("广州"),
      value: "guangzhou",
    ));
    cityList.add(DropdownMenuItem(
      child: new Text("深圳"),
      value: "shenzheng",
    ));
    cityList.add(DropdownMenuItem(
      child: new Text("新疆"),
      value: "新疆",
    ));
    return cityList;
  }
  var selectedCity;
  @override
  Widget build(BuildContext context) {
    return new Column(
      children: <Widget>[
        new DropdownButton(
            items: getCityList(),
            value: selectedCity,
            hint:new Text("请选择城市"),
            onChanged: (val){
              setState(() {
                this.selectedCity = val;
              });
            })
      ],
    );
  }

}